package org.example.volunteerend.config;

import org.example.volunteerend.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final JwtInterceptor jwtInterceptor;

    public WebMvcConfig(JwtInterceptor jwtInterceptor) {
        this.jwtInterceptor = jwtInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加JWT拦截器，拦截所有API请求
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/api/**")
                // 排除不需要登录的接口
                .excludePathPatterns(
                    "/api/users/register",
                    "/api/users/login",
                    "/api/project-categories/**",
                    "/api/projects",                   // 只排除项目列表查询
                    "/api/projects/{projectId:\\d+}"   // 只排除项目详情查询
                );
    }
} 